package com.qianxun.module.base.view;

import com.qianxun.module.base.rest.BaseRestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: huwei
 * @date: 2019/9/17 19:25
 * @version: 1.3.0
 */
public abstract class BaseViewController extends BaseRestController {

    @GetMapping(value = {"" ,"/" ,"/start" ,"/index" ,"/index.html" ,"/index.htm" ,"/home" ,"/home.html"})
    public ModelAndView index(ModelAndView modelAndView , HttpServletRequest request , HttpServletResponse response){
        modelAndView.setViewName(prefix().concat("/index.html"));
        return modelAndView;
    }

    @GetMapping(value = {"/toAdd"})
    public ModelAndView toAdd(ModelAndView modelAndView,Long id ,String key , HttpServletRequest request , HttpServletResponse response){
        modelAndView.setViewName(prefix().concat("/add.html"));
        modelAndView.addObject("id" ,id);
        modelAndView.addObject("key" ,key);
        return modelAndView;
    }

    @GetMapping(value = {"/toEdit"})
    public  ModelAndView toEdit(ModelAndView modelAndView ,Long id ,String key , HttpServletRequest request , HttpServletResponse response){
        modelAndView.setViewName(prefix().concat("/edit.html"));
        modelAndView.addObject("id" ,id);
        modelAndView.addObject("key" ,key);
        return modelAndView;
    }

    @GetMapping(value = {"/toDetail"})
    public ModelAndView toDetail(ModelAndView modelAndView ,Long id ,String key , HttpServletRequest request , HttpServletResponse response){
        modelAndView.setViewName(prefix().concat("/detail.html"));
        modelAndView.addObject("id" ,id);
        modelAndView.addObject("key" ,key);
        return modelAndView;
    }

    /**
     * 返回页面的前缀路径地址，格式如下：
     * module/test/
     * @return
     */
    protected abstract String prefix();

}
